<template>
  <div>
		<div>
      <el-form :inline="true">
        <el-form-item label="姓名">
          <el-input placeholder="请输入姓名" v-model="userName" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="入住日期">
          <el-date-picker placeholder="请选择入住日期" v-model="listQuery.startDate" :editable="false" :picker-options="pickerOptions" type="date"></el-date-picker>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="findUserByUsername">查询</el-button>
        </el-form-item>
      </el-form>
		</div>
    <!-- 表格渲染 -->
		<el-table border :fit="true" ref="tableData" max-height="700" style="width: 100%" :data="tableData">
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="u_id" v-if="false"></el-table-column>
      <el-table-column prop="roomNumber" label="房号"></el-table-column>
      <el-table-column prop="Status" label="状态" :formatter="orderStatus"></el-table-column>

      <el-table-column prop="orderTime" label="订单时间" width="160"></el-table-column>
      <el-table-column prop="arrireDate" label="到达时间" width="160"></el-table-column>
      <el-table-column prop="leaveDate" label="离开时间" width="160"></el-table-column>
      <el-table-column prop="realMoney" label="实收（元）"></el-table-column>
      <el-table-column prop="orderMoney" label="定价（元）"></el-table-column>
      <el-table-column prop="userPhone" label="手机号" width="170"></el-table-column>
      <el-table-column prop="user_remark" label="用户备注"></el-table-column>
      <el-table-column prop="admin_remark" label="备注"></el-table-column>
		</el-table>

  <el-row class="page-row">
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 50]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
  </el-row>

  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      userName:'',
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        name: undefined,
        startDate: this.getYesterday()
      },
      total: 0,
      pageSize: 20,
      currentPage: 1
    }
  },
  mounted () {
    this.getHome()
    this.loadData()
  },
  methods: {
     orderStatus(row) {
          console.log(row);
          if (row.orderStatus == 0) {
              row.Status = "未审核";
              return row.Status;
          } else if (row.orderStatus == 1) {
              row.Status = "审核通过";
              return row.Status;
          } else if (row.orderStatus == 2) {
              row.Status = "已入住";
              return row.Status;
          } else if (row.orderStatus == 3) {
              row.Status = "已完成订单";
              return row.Status;
          }else if (row.orderStatus == -1) {
              row.Status = "用户取消订单";
              return row.Status;
          } else if (row.orderStatus == -2) {
              row.Status = "拒绝";
              return row.Status;
          }
      },
    findUserByUsername(){
      console.log(this.userName);
      this.$axios.get("/ssms/admin/order/adminGetUserOrders?username="+this.userName,{headers:{'Content-Type':'application/json',
          responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          this.tableData = res.data.obj;

        }
      })
    },
    getHome(){
          this.$axios.get("/ssms/admin/order/getOrderByStatus?orderStatus=3",{headers:{'Content-Type':'application/json',
          responseType: "application/json"}})
      .then(res => {
        console.log(res.data);
        if(res.data.code === 0){
          this.tableData = res.data.obj;

        }
      })
  },
    loadData () {
      this.listQuery.currentPage = this.currentPage
      this.listQuery.pageSize = this.pageSize
    },
    search () {
      this.loadData()
    },
    getYesterday () {
      let day = new Date()
      day.setTime(day.getTime() - 24 * 60 * 60 * 1000)
      return day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate()
    },
    // 跳转页数
    handleCurrentChange (val) {
      this.currentPage = val
      this.loadData(this.listQuery)
    },
    // 改变分页大小
    handleSizeChange (val) {
      this.pageSize = val
      this.loadData(this.listQuery)
    }
  }
}
function timeFormatter (millionSeconds) {
  var time = new Date(millionSeconds)
  var y = time.getFullYear()
  var m = time.getMonth() + 1
  var d = time.getDate()
  var h = time.getHours()
  var mm = time.getMinutes()
  var s = time.getSeconds()
  return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s)
}
function add0 (m) {
  return m < 10 ? '0' + m : m
}
</script>

<style scoped>
.page-row {
  text-align: right;
  margin-top: 5px
}
</style>

